package com.iwuke.dance.util.merchants_connect;


import java.util.ArrayList;
import java.util.List;


/**
 * @author: 魏从响
 * @date: 2025/9/12
 */
public class NetStateChangeReceiver /*extends BroadcastReceiver */{

//    private NetworkType mType = NetworkUtil.getNetworkType(LPWHApplication.getContext());

    private static class InstanceHolder{
        private static final NetStateChangeReceiver INSTANCE = new NetStateChangeReceiver();
    }

    private List<NetStateChangeObserver> mObservers = new ArrayList<>();

//    @Override
//    public void onReceive(Context context, Intent intent) {
//        if (ConnectivityManager.CONNECTIVITY_ACTION.equals(intent.getAction())){
//            NetworkType networkType = NetworkUtil.getNetworkType(context);
//            notifyObservers(networkType);
//        }
//    }

//    public static void registerReceiver(Context context){
//        IntentFilter intentFilter = new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION);
//        context.registerReceiver( InstanceHolder.INSTANCE,intentFilter);
//    }
//
//    public static void unRegisterReceiver(Context context){
//        context.unregisterReceiver( InstanceHolder.INSTANCE);
//    }
//
//    public static void registerObserver(NetStateChangeObserver observer){
//        if (observer == null) {
//            return;
//        }
//        if (!InstanceHolder.INSTANCE.mObservers.contains(observer)){
//            InstanceHolder.INSTANCE.mObservers.add(observer);
//        }
//    }

    public static void unRegisterObserver(NetStateChangeObserver observer){
        if (observer == null) {
            return;
        }
        if (InstanceHolder.INSTANCE.mObservers == null) {
            return;
        }
        InstanceHolder.INSTANCE.mObservers.remove(observer);
    }

//    private void notifyObservers(NetworkType networkType){
//        if (mType == networkType) {
//            return;
//        }
//        mType = networkType;
//        if (networkType == NetworkType.NETWORK_NO){
//            for (NetStateChangeObserver observer : mObservers){
//                observer.onNetDisconnected();
//            }
//        }else {
//            for (NetStateChangeObserver observer : mObservers){
//                observer.onNetConnected(networkType);
//            }
//        }
//    }

}
